/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2023-12-26
 * Time: 16:38
 */
abstract class Account {
    private String name, aid;
    protected double balance;
    private String status;

    public Account(double balance, String status) {
        this.balance = balance;
        this.status = status;
    }

    public abstract void deposit(double a);

    public void withdraw(double amount, String accountHolder) throws WithdrawException, BlockedException {
        if ("blocked".equals(status)) {
            throw new BlockedException("账户被冻结，无法取款。");
        } else if (amount > balance) {
            throw new WithdrawException(balance, amount, accountHolder);
        } else {
            balance -= amount;
            System.out.println(accountHolder + "取款" + amount + "成功，当前余额：" + balance);
        }
    }

    public abstract double getBalance();
}

class BlockedException extends Exception {
    public BlockedException(String message) {
        super(message);
    }
}

class CreditAccount extends Account {
    int year, lineofcredit;

    public CreditAccount(double balance, String status, int year, int lineofcredit) {
        super(balance, status);
        this.year = year;
        this.lineofcredit = lineofcredit;
    }

    public void deposit(double a) {
        balance += a;
    }

    @Override
    public double getBalance() {
        return balance;
    }
}

class WithdrawException extends Exception {
    private double balance;// 账户余额
    private double amount;// 取款额
    private String accountHolder;// 取款人

    public WithdrawException(double balance, double amount, String accountHolder) {
        this.balance = balance;
        this.amount = amount;
        this.accountHolder = accountHolder;
    }

    @Override
    public String getMessage() {
        return accountHolder + "，账号余额：" + balance + "，取款额：" + amount + "，原因：透支。";
    }
}

public class Test {
    public static void main(String[] args) {
        CreditAccount account = new CreditAccount(500, "normal", 1, 1000);

        try {
            account.withdraw(300, "张三");

            // 模拟账户被冻结
            account = new CreditAccount(500, "blocked", 1, 1000);
            account.withdraw(300, "李四");
        } catch (WithdrawException e) {
            System.out.println("取款异常：" + e.getMessage());
        } catch (BlockedException e) {
            System.out.println(e.getMessage());
        }
    }
}